package com.stormrage.edu.dao.student.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.student.StuNoticeDao;
import com.stormrage.entity.student.StuNotice;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: StuNoticeDaoImpl.java
 * @Package com.stormrage.edu.dao.student.impl
 * @Description: 通知 Dao
 * @author www.stormragetech.com
 * @date 2016年4月16日
 * @version V1.0
 */
@Repository
public class StuNoticeDaoImpl extends MysBaseDao implements StuNoticeDao {

	private static final Logger logger = LoggerFactory.getLogger(StuNoticeDaoImpl.class);

	@Override
	public Integer create(final StuNotice arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 StuNoticeDao 】-【 create 】-【 STARTED 】");

		final String query = "INSERT INTO stu_notice (title, content, datetime, bunch_id)"
				+ " VALUES (:title, :content, :datetime, :bunchId)";
		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】-【 StuNoticeDao 】-【 create 】-【 COMPLETED 】");
		return index;

	}

	@Override
	public void update(final StuNotice arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 StuNoticeDao 】-【 update 】-【 STARTED 】");

		final String query = "UPDATE stu_notice SET title = :title, content = :content, datetime = :datetime WHERE id = :id";
		update(query, arg0);

		logger.debug(" 【 Dao 】-【 StuNoticeDao 】-【 update 】-【 COMPLETED 】");

	}

	@Override
	public Integer queryCountByBunchId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 StuNoticeDao 】-【 queryCountByBunchId 】-【 STARTED 】");

		final String query = "SELECT COUNT(*) FROM stu_notice WHERE bunch_id = :bunchId ORDER BY id DESC";
		Integer count = queryCount(query, map);

		logger.debug(" 【 Dao 】-【 StuNoticeDao 】-【 queryCountByBunchId 】-【 COMPLETED 】");
		return count;

	}

	@Override
	public StuNotice queryById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 StuNoticeDao 】-【 QueryById 】-【 STARTED 】");

		final String query = "SELECT * FROM stu_notice WHERE id = :id";
		StuNotice entity = queryObject(query, StuNotice.class, map);

		logger.debug(" 【 Dao 】-【 StuNoticeDao 】-【 QueryById 】-【 COMPLETED 】");
		return entity;

	}

	@Override
	public List<StuNotice> queryListByBunchId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 StuNoticeDao 】-【 QueryListByBunchId 】-【 STARTED 】");

		final String query = "SELECT * FROM stu_notice WHERE bunch_id = :bunchId ORDER BY id DESC";
		List<StuNotice> array = queryList(query, StuNotice.class, map);

		logger.debug(" 【 Dao 】-【 StuNoticeDao 】-【 QueryListByBunchId 】-【 COMPLETED 】");
		return array;

	}

}
